-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(model): execute valid write operations if calling bulkWrite()
with ordered: false
#13218
Conversation
…ith ordered: false Fix #13176
You have successfully added a new CodeQL configuration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i am not very familiar with this part of the code, so i cannot say much about it
I'm not thrilled with the fact that bulkWrite() doesn't throw an error if some operations failed validation, but that is consistent with how insertMany() works
i also think if there are errors it should throw by default, but maybe also allow a option like applyValidOperations
or something (which is by default false
in a next major release)
@hasezoey it is a reasonable idea to throw an error if errors occurred. However, I'd like to add that in a separate PR because I would like to add that option to Probably call the option |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
} | ||
if (ops.length === 0) { | ||
return cb(null, getDefaultBulkwriteResult()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check should be moved somewhere above the if (ordered) {
block. Please see #14117
Fix #13176
Summary
Make the
bulkWrite()
API more consistent withinsertMany()
:If
ordered: false
, validate all write operations, and strip out any invalid ones. Execute the valid operations.mongoose.validationErrors
to result to indicate which operations failed validation.mongoose.validationErrors
to the error to indicate which operations failed validation.I'm not thrilled with the fact that
bulkWrite()
doesn't throw an error if some operations failed validation, but that is consistent with howinsertMany()
works. And I'd prefer to maintain consistency, and consider changing the API for the next major release. What do you think @hasezoey ?Examples